#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Experimental/Credit/RiskyBond.h>
#pragma unmanaged 
#include <ql\experimental\credit\riskybond.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL;
using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Experimental { namespace Credit {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IRiskyFloatingBond
	public ref class CRiskyFloatingBond : 
            public CRiskyBond,
            public Cephei::QL::Experimental::Credit::IRiskyFloatingBond
	{
	protected: 
		boost::shared_ptr<QuantLib::RiskyFloatingBond>* _ppRiskyFloatingBond;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::RiskyFloatingBond>* _phRiskyFloatingBond;
#endif
		Object^ _RiskyFloatingBondOwner;     // reference to object that manages the storage for this object
	internal:
		CRiskyFloatingBond (String^ name, Cephei::QL::ICurrency^ ccy, Double recoveryRate, Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^ defaultTS, Cephei::QL::Times::ISchedule^ schedule, Cephei::QL::Indexes::IIborIndex^ index, Int32 fixingDays, Double spread, Cephei::IVector<Double>^ notionals, Cephei::QL::Termstructures::IYieldTermStructure^ yieldTS, Cephei::QL::IPricingEngine^ QL_Pricer);
        CRiskyFloatingBond (boost::shared_ptr<QuantLib::RiskyFloatingBond>& childNative, Object^ owner);
        CRiskyFloatingBond (QuantLib::RiskyFloatingBond& childNative, Object^ owner);
        CRiskyFloatingBond (CRiskyFloatingBond^ copy);
        CRiskyFloatingBond (System::Type^ t);
#ifdef STRUCT
        CRiskyFloatingBond (QuantLib::RiskyFloatingBond childNative);
#endif       
#ifdef HANDLE
		CRiskyFloatingBond (QuantLib::Handle<QuantLib::RiskyFloatingBond>& childNative, Object^ owner);
		CRiskyFloatingBond (QuantLib::Handle<QuantLib::RiskyFloatingBond> childNative);
#endif
		virtual ~CRiskyFloatingBond ();
		!CRiskyFloatingBond ();

	internal:
		QuantLib::RiskyFloatingBond& GetReference ();
		boost::shared_ptr<QuantLib::RiskyFloatingBond>& GetShared ();
		QuantLib::RiskyFloatingBond* GetPointer ();
        void SetRiskyFloatingBond (boost::shared_ptr<QuantLib::RiskyFloatingBond> native)
        {
            if (_ppRiskyFloatingBond != NULL)
                delete _ppRiskyFloatingBond;
            _ppRiskyFloatingBond = new boost::shared_ptr<QuantLib::RiskyFloatingBond> (native);
            SetRiskyBond (boost::dynamic_pointer_cast<QuantLib::RiskyBond> (*_ppRiskyFloatingBond));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::RiskyFloatingBond>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property Cephei::IVector<Cephei::QL::ICashFlow^>^ Cashflows 
        {
		    virtual Cephei::IVector<Cephei::QL::ICashFlow^>^ get () ;
        }
        property DateTime EffectiveDate 
        {
		    virtual DateTime get () ;
        }
        property Cephei::IVector<Cephei::QL::ICashFlow^>^ InterestFlows 
        {
		    virtual Cephei::IVector<Cephei::QL::ICashFlow^>^ get () ;
        }
        property DateTime MaturityDate 
        {
		    virtual DateTime get () ;
        }
		virtual Double Notional (Microsoft::FSharp::Core::FSharpOption<DateTime>^ date) ;
        property Cephei::IVector<Cephei::QL::ICashFlow^>^ NotionalFlows 
        {
		    virtual Cephei::IVector<Cephei::QL::ICashFlow^>^ get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CRiskyFloatingBond_Factory : public System::MarshalByRefObject,  public IRiskyFloatingBond_Factory
	{
	public:
        virtual IRiskyFloatingBond^ Create (String^ name, Cephei::QL::ICurrency^ ccy, Double recoveryRate, Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^ defaultTS, Cephei::QL::Times::ISchedule^ schedule, Cephei::QL::Indexes::IIborIndex^ index, Int32 fixingDays, Double spread, Cephei::IVector<Double>^ notionals, Cephei::QL::Termstructures::IYieldTermStructure^ yieldTS, Cephei::QL::IPricingEngine^ QL_Pricer);
    };
   
/*Cephei*/ } /*QL*/ } /*Experimental*/ } /*Credit */}
